local lib = {}

--- 判断使用/打出事件是否是在使用手牌
---@param player ServerPlayer @ 要判断的使用者
------@param event GameEvent @ 事件
---@return boolean
lib.IsUsingHandcard = function(player, event)
    local data = event.data[1]
    local cards = data.card:isVirtual() and data.card.subcards or {data.card.id}
    if #cards == 0 then return false end
    local yes = true
    local use = event
    use:searchEvents(GameEvent.MoveCards, 1, function(e)
        if e.parent and e.parent.id == use.id then
            local subcheck = table.simpleClone(cards)
            for _, move in ipairs(e.data) do
                if (move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonResonpse) then
                    for _, info in ipairs(move.moveInfo) do
                        if table.removeOne(subcheck, info.cardId) and info.fromArea ~= Card.PlayerHand then
                            yes = false
                            return true
                        end
                    end
                end
            end
            if #subcheck == 0 then
                return true
            end
        end
    end)
    return yes
end

return lib